package com.gxa.finance.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.gxa.common.commons.JsonResult;
import com.gxa.common.commons.R;
import com.gxa.finance.mapper.OfficeTransferReviewMapper;
import com.gxa.finance.pojo.Bill;
import com.gxa.finance.service.OfficeTransferReviewService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

@Service
public class OfficeTransferReviewServiceImpl extends ServiceImpl<OfficeTransferReviewMapper, Bill> implements OfficeTransferReviewService {

    @Autowired
  private OfficeTransferReviewMapper officeTransferReviewMapper;

  //1、分页查询
    @Override
    public JsonResult findOfficeDetailsReviewList(Integer currentPage, Integer pageSize) {
            JsonResult jsonResult = new JsonResult();
        try {
            QueryWrapper<Bill> billQueryWrapper = new QueryWrapper();
            billQueryWrapper.eq("payment","线下支付");
            Page<Bill> page = new Page<>(currentPage,pageSize);
            Page<Bill> billPage = officeTransferReviewMapper.selectPage(page, billQueryWrapper);
            jsonResult.setCode(200);
            jsonResult.setMsg("查询成功");
            jsonResult.setCount((int) billPage.getTotal());
            jsonResult.setData(billPage.getRecords());
        }catch (Exception e){
            e.printStackTrace();
            jsonResult.setCode(500);
            jsonResult.setMsg("系统开小差了");
        }

        return jsonResult;
    }

    //高级查询
    @Override
    public R findfindOfficeDetailsReviewSeniorList(Bill bill) {

        R r = new R();
        try {
            List<Bill> offlineTransferReviewList = officeTransferReviewMapper.findfindOfficeDetailsReviewSeniorList(bill);
            r.setCode(200);
            r.setMsg("查询成功");
            r.setData(offlineTransferReviewList);
        }catch (Exception e){
            e.printStackTrace();
            r.setCode(500);
            r.setMsg("网络开小差");
        }

        return r;
    }

    //修改
    @Override
    public R updatefindOfficeDetailsReview(Bill bill) {
        R r = new R();
        int result = officeTransferReviewMapper.updateById(bill);
        if (result > 0) {
            r.setCode(200);
            r.setMsg("修改成功");
            r.setData(result);
        }else {
            r.setCode(500);
            r.setMsg("系统出小差了，请联系管理员");
        }
        return r;
    }


}
